package com.ruyuan.commodity.common.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruyuan.commodity.model.goods.dos.TagGoodsDO;
import com.ruyuan.commodity.model.goods.vo.GoodsSelectLine;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Map;

/**
 * TagGoods的Mapper
 */
@Repository
public interface TagGoodsMapper extends BaseMapper<TagGoodsDO> {

    /**
     * 查询标签商品
     * @param tagId 标签id
     * @param num 数量
     * @return
     */
    @Results({
            @Result(column = "goods_id", property = "goodsId", id = true),
            @Result(column = "goods_name", property = "goodsName"),
            @Result(column = "price", property = "price"),
            @Result(column = "sn", property = "sn"),
            @Result(column = "thumbnail", property = "thumbnail"),
            @Result(column = "big", property = "big"),
            @Result(column = "quantity", property = "quantity"),
            @Result(column = "buy_count", property = "buyCount"),
            @Result(column = "comment_num", property = "commentNum"),
    })
    @Select("select g.goods_id,g.goods_name,g.price,g.sn,g.thumbnail,g.big,g.quantity,g.buy_count,g.comment_num from es_tag_goods r " +
            "inner join es_goods g on g.goods_id=r.goods_id " +
            "where g.disabled=1 and g.market_enable=1 and  r.tag_id=#{tag_id} limit 0,#{num}")
    List<GoodsSelectLine> queryTagGoods(@Param("tag_id") Long tagId, @Param("num") Integer num);

    /**
     * 查询标签商品分页
     * @param iPage 分页条件
     * @param tagId 标签id
     * @return
     */
    @ResultType(value = Map.class)
    @Select("select g.goods_id,g.goods_name,g.price,g.buy_count,g.enable_quantity,g.thumbnail from es_tag_goods r " +
            "LEFT JOIN es_goods g ON g.goods_id=r.goods_id " +
            "where g.disabled=1 and g.market_enable=1 and r.tag_id=#{tag_id}")
    IPage<Map> queryTagGoodsPage(IPage iPage,@Param("tag_id") Long tagId);


}
